﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;

namespace Assets.Script
{
    class InstallPanelControl
    {
        private InstallPanelView view;
        InstallPanelModel model;
        bool nowSountState = true, nowHapticState = true;

        public InstallPanelControl(InstallPanelView installPanelView)
        {
            this.view = installPanelView;
            model = new InstallPanelModel();
            BindEvent();
        }

        private void BindEvent()
        {
            view.closeBtn.onClick.AddListener (() =>
            {
                UIManager.Ins.CloseUI(UIName.InstallPanel);
            });
            view.soundBtn.onClick.AddListener(() =>
            {
                nowSountState = !nowSountState;
                RefureTextShow(view.soundBtn,nowSountState, view.soundText, view.soundImg);
            });
            view.hapticBtn.onClick.AddListener(() =>
            {
                nowHapticState = !nowHapticState;
                RefureTextShow(view.hapticBtn, nowHapticState, view.hapticText, view.hapticImg);
            });
        }

        private void RefureTextShow(Button btn, bool nowState, Text showText, RectTransform showTran)
        {
            if (nowState)
            {
                showText.text = "ON";
                showText.alignment = TextAnchor.MiddleLeft;
                showTran.anchorMax = new Vector2(1, 0.5f);
                showTran.anchorMin = new Vector2(1, 0.5f);
                showTran.anchoredPosition = new Vector2(-27, showTran.anchoredPosition.y);
                btn.gameObject.GetComponent<Image>().color = Color.blue;
                Debug.Log("开启");
                //showTran.pivot = new Vector2(0, 0);
            }
            else
            {
                showText.text = "OFF";
                showText.alignment = TextAnchor.MiddleRight;
                showTran.anchorMax = new Vector2(0, 0.5f);
                showTran.anchorMin = new Vector2(0, 0.5f);
                showTran.anchoredPosition = new Vector2(27, showTran.anchoredPosition.y);
                btn.gameObject.GetComponent<Image>().color = Color.gray;
                Debug.Log("关闭");
                //showTran.pivot = new Vector2(1, 1);
            }
        }
    }
}
